# -*- coding:utf-8 -*-
from conf.setting import CASE_DATA_PATH
from conf.setting import BODY_PATH

import os

from tools.operate_config import get_yaml,OperateConfig
from tools.operate_json import OperationJson


class GetHeaderjson:

    def __init__(self,env=None):
        if env is not None:
            self.env = env
        else:
            self.env = OperateConfig().get_node_value('ENV', 'env')   #获取的是172.16.1.20

            self.headers_json = os.path.join(BODY_PATH, "headers.json")  # 请求头json 文件 ；os.path.jion用于拼接多个路径字符串


    #获取请求头
    #获取headers.json里名为"s_login_headers”的json串
    def get_s_login_headers(self):
        return OperationJson(self.headers_json).key_get_data(self.env,"s_login_headers")  #读json文件，例如：请求体-body
    #获取headers.json里名为"s_headers”的json串
    def get_s_headers(self):
        return OperationJson(self.headers_json).key_get_data(self.env,"s_headers")
    #用于登录成功将获取到的token值set进去：set_s_headers，往json文件里set字段值
    def set_s_headers(self,s_token):
        return OperationJson(self.headers_json).write_datas(s_token,self.env, "s_headers", "sToken")
    def get_login(self):
        return OperationJson(self.headers_json)


#读取请求体body.json文件
class GetcJson:
    def __init__(self,env=None):
        if env is not None:
            self.env = env
        else:

            self.env = OperateConfig().get_node_value('ENV', 'env')
            self.body_json = os.path.join(CASE_DATA_PATH, "body.json")  # 按配置文件设置的环境读取，比如这里读取的文件就是qa1_c.json


    def get_login(self):
        return OperationJson(self.body_json).key_get_data("Login")
    #【设备操作】

    #1、TTS请求(将参数写进body里)
    def set_playDuration(self, s_playDuration):
        return OperationJson(self.body_json).write_datas(s_playDuration, "speechSynthesisPlay", "requestData","playDuration")
    def set_timeType(self,s_timeType):
        return OperationJson(self.body_json).write_datas(s_timeType,"speechSynthesisPlay", "requestData","timeType")
    def set_tts_content(self,tts_content):
        return OperationJson(self.body_json).write_datas(tts_content,"speechSynthesisPlay", "requestData","content")
    def get_tts(self):
        return OperationJson(self.body_json).key_get_data("speechSynthesisPlay")


    #2、音频播放请求
    def set_audio(self, file_name):
        return OperationJson(self.body_json).write_datas(file_name, "audioPlay", "requestData", "audioName")
    def set_audio_Duration(self, playDuration):
        return OperationJson(self.body_json).write_datas(playDuration, "audioPlay", "requestData","playDuration")
    def set_audio_timeType(self, timeType):
        return OperationJson(self.body_json).write_datas(timeType, "audioPlay", "requestData",  "timeType")
    def get_audio_body(self):
        return OperationJson(self.body_json).key_get_data("audioPlay")


    #3、调节音量
    def set_volume(self,volume):
        return OperationJson(self.body_json).write_datas(volume, "volumeSet", "requestData","volume")
    def get_volume(self):
        return OperationJson(self.body_json).key_get_data("volumeSet")

    def set_volume_deviceId(self, deviceId):
        return OperationJson(self.body_json).write_datas(deviceId, "volumeSet", "requestData","deviceId")


    #4、电源操作
    def set_relaymodel(self, relayModel):
        return OperationJson(self.body_json).write_datas(relayModel, "relayOperate", "requestData", "relayModel")
    def set_relaysatus(self, relayStatus):
        return OperationJson(self.body_json).write_datas(relayStatus, "relayOperate", "requestData", "relayStatus")

    def set_relay_deviceId(self, deviceId):
        return OperationJson(self.body_json).write_datas(deviceId, "relayOperate", "requestData","deviceId")
    def get_relay(self):
        return OperationJson(self.body_json).key_get_data("relayOperate")

    #5、停止播放
    def get_audiostop(self):
        return OperationJson(self.body_json).key_get_data("audioStop")
    def set_audiostop_deviceId(self, deviceId):
        return OperationJson(self.body_json).write_datas(deviceId, "audioStop", "requestData", "deviceId")

    #6、告警灯下发
    def set_lightType(self, lightType):
        return OperationJson(self.body_json).write_datas(lightType, "lightModeSet", "requestData", "protocolType")
    def set_lightmodeId(self, lightmodeId):
        return OperationJson(self.body_json).write_datas(lightmodeId, "lightModeSet", "requestData", "modeId")
    def get_light(self):
        return OperationJson(self.body_json).key_get_data("lightModeSet")

    #7、删除设备端的音频文件
    def set_storageName(self, storageName):
        return OperationJson(self.body_json).write_datas(storageName, "audioDelete", "requestData", "storageName")
    def get_audiodelete(self):
        return OperationJson(self.body_json).key_get_data("audioDelete")

    #8、重启设备
    def get_reboot(self):
        return OperationJson(self.body_json).key_get_data("reboot")
    #9、开关屏操作
    def set_Screen_switch(self,operateType):
        return OperationJson(self.body_json).write_datas(operateType, "switchScreen", "requestData", "operateType")
    def get_switchInfBoardScreen(self):
        return OperationJson(self.body_json).key_get_data("switchScreen")

    #10、录音采集操作
    def set_recordDuration(self, recordDuration):
        return OperationJson(self.body_json).write_datas(recordDuration, "deviceMicRecordCollection", "requestData", "recordDuration")
    def get_MicRecord_Collection(self):
        return OperationJson(self.body_json).key_get_data("deviceMicRecordCollection")
    #11、情报板屏参配置
    def set_screenType(self, screenType):
        return OperationJson(self.body_json).write_datas(screenType, "updateInfoBoard", "requestData","screenType")
    def set_screenSize(self, screenSize):
        return OperationJson(self.body_json).write_datas(screenSize, "updateInfoBoard", "requestData","screenSize")
    def get_InfoBoard(self):
        return OperationJson(self.body_json).key_get_data("updateInfoBoard")

    #12、情报板配置
    def set_ledeffectType(self, effectType):
        return OperationJson(self.body_json).write_datas(effectType, "informationBoardSet", "requestData","effectType")
    def set_ledcontent(self, ledcontent):
        return OperationJson(self.body_json).write_datas(ledcontent, "informationBoardSet", "requestData","content")
    def set_ledfontColor(self, fontColor):
        return OperationJson(self.body_json).write_datas(fontColor, "informationBoardSet", "requestData","fontColor")
    def get_BoardSetInfo(self):
        return OperationJson(self.body_json).key_get_data("informationBoardSet")
















    #------------------------------------------------------------------------
    #【设备管理】
    #1、获取已上传至媒体库的音频文件
    def get_media_list_info(self):
        return OperationJson(self.body_json).key_get_data("queryMediaList")

    #2、查询情报板屏参配置和当前显示内容
    def get_InfoBoardInfo(self):
        return OperationJson(self.body_json).key_get_data("queryInfoBoardInfo")


    #3、继电器操作
    def set_relaymodel(self, relayModel):
        return OperationJson(self.body_json).write_datas(relayModel, "relayOperate", "requestData", "relayModel")

    def set_relaysatus(self, relayStatus):
        return OperationJson(self.body_json).write_datas(relayStatus, "relayOperate", "requestData", "relayStatus")

    def get_relay(self):
        return OperationJson(self.body_json).key_get_data("relayOperate")
    # 4、获取已上传至设备的音频
    def get_upload_audioList(self):
        return OperationJson(self.body_json).key_get_data("queryUploadAudioList")

    #5、音频文件上传至设备端
    def set_downloadurl(self,downloadUrl):
        return OperationJson(self.body_json).write_datas(downloadUrl, "audioUpload", "requestData", "downloadUrl")
    def get_audioUpload(self):
        return OperationJson(self.body_json).key_get_data("audioUpload")

    # 6、查询设备列表
    def get_device_list(self):
        return OperationJson(self.body_json).key_get_data("queryDevicelist")

    # 7、查询设备端录音采集文件列表
    def get_MicRecord_list(self):
        return OperationJson(self.body_json).key_get_data("queryDeviceRecordList")

    # 8、查询设备端录音采集文件信息
    def set_recordId(self, recordId):
        return OperationJson(self.body_json).write_datas(recordId, "queryDeviceRecordInfo", "requestData", "recordId")
    def get_DeviceRecordInfo(self):
        return OperationJson(self.body_json).key_get_data("queryDeviceRecordInfo")



























